
<template>
    <el-dropdown class=" g-flex-align-cross-center g-color-fff g-height100" style="padding: 0 5px;" @command="applicationSwitch"
                 v-loading="userinfoLoading"
                 element-loading-spinner="el-icon-loading">
        <div class="g-pointer g-height100 g-flex-align-cross-center" title="切换应用"> {{currentApplication.name}}<i class="el-icon-arrow-down el-icon--right"></i></div>
        <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-for="(app,index) in applications" :command="app" :key="index"
                              :disabled="currentApplication.id == app.id"
            >{{app.name}}</el-dropdown-item>
        </el-dropdown-menu>
    </el-dropdown>
</template>


<script>
    import storage from '../../../../common-util/src/tools/StorageTools.js'
    export default {
        props:{
            userinfoLoading:{
                type:Boolean,
                default: false
            },
            applications:{
                type: Array,
                default: function () {
                    return []
                }
            }
        },
        data (){
            return {
                currentApplication: {}

            }
        },
        created(){
            // currentApplication在portal项目选择应用时设置和applicationSwitch方法中设置
            this.currentApplication = storage.get("currentApplication")
            if(!this.currentApplication){
                this.currentApplication = {
                    name:'混合模式',
                    id:null
                }
            }
        },
        mounted(){
        },
        methods:{
            applicationSwitch(command){
                storage.set("currentApplication",command)
                this.currentApplication = command
                // 该事件是在portal项目app.vue中监听
                this.$bus.$emit('getFuncData')
            }
        }
    }
</script>

<style scoped>

</style>